import 'dart:typed_data';

extension MyUint8ListExtension on Uint8List {
  String toHexString({bool showIndex = false, bool showLength = false}) {
    String str = "[";

    if (showLength) {
      str = "$length [";
    }

    int lastIndex = length - 1;
    for (int i = 0; i < length; i++) {
      var v = this[i].toRadixString(16).padLeft(2, "0").toUpperCase();
      if (showIndex) {
        str += "($i)";
      }
      if (i < lastIndex) {
        str += "$v, ";
      } else {
        str += v;
      }
    }
    str += "]";
    return str;
  }
}
